package com.shi.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * Author 史豪通
 * Date 2024/08/30 19:07
 */
public class Utils {

    public static List<Object> getList(List<Object> myList, int pageNum, int pageSize) {
        int listSize = myList.size();

        int startIndex, endIndex;

        do {
            startIndex = (pageNum-- - 1) * pageSize;
            endIndex = startIndex + pageSize - 1;
        }
        while (listSize - 1 < startIndex && pageNum > 0);

        if (listSize < pageSize) startIndex = 0;

        List<Object> middleAnyTen = new ArrayList<>();
        for (int i = startIndex; i <= endIndex && i < listSize; i++) {
            middleAnyTen.add(myList.get(i));
        }

        return middleAnyTen;
    }
}
